package com.hepinghospital.user.ui.activity.consult;

import android.content.DialogInterface;
import android.widget.ImageView;
import android.widget.TextView;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseActivity;
import com.hepinghospital.user.fw_permission.FloatWinPermissionCompat;
import com.hepinghospital.user.util.ImageLoaderHelper;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by HP on 2018/9/20.
 */

public class PhoneActivity extends BaseActivity {
    @BindView(R.id.tv_name)
    TextView tv_name;
    @BindView(R.id.img_head)
    ImageView img_head;
    String name;
    String url;

    @Override
    protected void initViews() {
        checkPermissionAndShow();
    }


    @Override
    protected void initData() {
        name = getIntent().getStringExtra("doctor");
        url = getIntent().getStringExtra("doctorPicture");
        tv_name.setText(name);
        ImageLoaderHelper.getInstance().GlideImageLoader(this, url, img_head, R.mipmap.touxiang);
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.activity_phone;
    }

    @OnClick(R.id.btn_accept)
    void btn_accept() {
        setResult(RESULT_OK);
        finish();
    }

    @OnClick(R.id.btn_decline)
    void btn_decline() {
        setResult(RESULT_CANCELED);
        finish();
    }


    protected void checkPermissionAndShow() {
        // 检查是否已经授权
        if (FloatWinPermissionCompat.getInstance().check(this)) {
        } else {
            // 授权提示
            new androidx.appcompat.app.AlertDialog.Builder(this).setTitle("悬浮窗权限未开启")
                    .setMessage("你的手机没有授权" + this.getString(R.string.app_name) + "获得悬浮窗权限，视频悬浮窗功能将无法正常使用")
                    .setPositiveButton("开启", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // 显示授权界面
                            try {
                                FloatWinPermissionCompat.getInstance().apply(PhoneActivity.this);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    })
                    .setNegativeButton("取消", (dialog, which) -> {
                        setResult(RESULT_CANCELED);
                        finish();
                    }).show();
        }
    }
}
